/**
 * kl yy-ds @2021
 */
package com.cxps.server.product.controller;

import com.cxps.server.product.service.ProductService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 商品控制层
 *
 * @author YouCai.Liu
 * @since 2021/11/12
 * ...
 */
@Api(tags = "商品批量处理API")
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 将商品在MySQL里的数据转换到ES索引里
     *
     * @return
     * @throws IOException
     */
    @GetMapping("/batchEs")
    public String batchEs() {
        productService.batchEs();
        return "SUCCESS";
    }

    /**
     * 根据ID将数据同步到ES
     * @return
     */
    @GetMapping("/batchEsByIds")
    public String batchEsByIds(@RequestParam String[] ids) {
        productService.batchEsByIds(ids);
        return "SUCCESS";
    }

    /**
     * 根据ID将数据同步到ES
     * @return
     */
    @GetMapping("/delEsByIds")
    public String delEsByIds(@RequestParam String[] ids) throws IOException {
        productService.delEsByIds(ids);
        return "SUCCESS";
    }

    /**
     * 将商品分类预先缓存到Redis
     *
     * @return
     * @throws IOException
     */
    @GetMapping("/cacheProductType")
    public String cacheProductType() {
        productService.cacheProductType();
        return "SUCCESS";
    }

    /**
     * 获取缓存
     *
     * @param key
     * @return
     */
    @GetMapping("/getCache")
    public String getCache(@RequestParam String key) {
        return productService.getCache(key);
    }


}
